#include<stdio.h>
int main()
{
int i, j, n = 0, a[100][100] = { 1 };
while (n < 1 || n>99)
{
printf("请输入杨辉三角形的行数:");
scanf_s("%d", &n);
}
for (i = 1; i < n; i++)
{
a[i][0] = 1;
for (j = 1; j <= i; j++)
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
}
for (i = 0; i < n; i++)
{
for (j = 0; j <= i; j++)
printf("%5d", a[i][j]);
printf("\n");
}
return 0;
}
用c语言实现杨辉三角
最新推荐文章于 2023-10-08 21:50:49 发布